﻿
using Domain.Entitys;
using Domain.Repositorys;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repositorys
{
    public class CPCRepositoy : ICPCRepositoy
    {
        private readonly MyDbContext myDbContext;

        public CPCRepositoy(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }
  

        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="cPC"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> CPCAddAsync(CPC cPC)
        {
            await myDbContext.CPC.AddAsync(cPC);
            return  await myDbContext.SaveChangesAsync();
        }
        /// <summary>
        /// 公共字段设置删除
        /// </summary>
        /// <param name="cPC"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> CPCDeleteAsync(CPC cPC)
        {
            myDbContext.CPC.Remove(cPC);
            return await myDbContext.SaveChangesAsync();
        }
        /// <summary>
        /// 按照条件查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>


        /// <summary>
        /// 数据显示
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<IEnumerable<CPC>> CPCselectAsync()
        {
          return  await myDbContext.CPC.ToListAsync();
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task< List<CPC>> SelectCount(int pageIndex, int pageSize)
        {
            return await  myDbContext.CPC.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
        }
        /// <summary>
        /// 总页数
        /// </summary>
        /// <returns></returns>
        public int SelectCount()
        {
           return myDbContext.CPC.Count();
        }

      public    async Task<List<CPC>> CPCselectaAsync(int pageIndex, int pageSize, string name)
        {
            List<CPC> list = await myDbContext.CPC.Where(c => c.AttributeKind == name).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
            return list;
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        async Task <List<CPC>> ICPCRepositoy.CPCselectAsync(int pageIndex, int pageSize)
        {
            return await myDbContext.CPC.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
        }
        /// <summary>
        /// 薪资管理设置
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public int SelectCounta(string name)
        {
            return myDbContext.CPC.Where(e => e.AttributeKind == name).Count();
        }
        /// <summary>
        /// 薪酬设置新增
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> CPCxinz(CPC cPC)
        {
            await myDbContext.CPC.AddAsync(cPC);
            return await myDbContext.SaveChangesAsync();
        }

        /// <summary>
        /// 使用属性种类查询全部属性数据
        /// </summary>
        /// <param name="kind"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<CPC>> CPCFillAsync(string kind)
        {
            return await myDbContext.CPC.Where(c => c.AttributeKind == kind).ToListAsync();
        }
    }
}
